package com.hey.amqpdemo.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;

/**
 * @ClassName QueueListener
 * @Author hey
 * @Date 2019/5/9 11:32
 **/
public class QueueListener implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        try {

            message.getMessageProperties().getConsumerTag();
            System.out.println( message.getMessageProperties().getConsumerTag());
            String message1 = new String(message.getBody(), "UTF-8");
            System.out.println("获取消息'" + message1 + "'");

//            channel.basicGet(); //每次消费一个消息
//            channel.basicQos(1);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void containerAckMode(AcknowledgeMode mode) {

    }
}
